FROM golang:1.20-alpine as builder

RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache ca-certificates tzdata
RUN apk add git openssh

# ENV 设置环境变量
ENV GOOS="linux"
ENV GOPROXY="https://goproxy.cn,direct"
ENV GOINSECURE="gitea.in"
ENV GOPRIVATE="gitea.in"

WORKDIR /build

COPY . .

RUN go mod download \
& go build -o datahub main.go

FROM alpine:3.16

LABEL maintainer="zhuhy@jnsec.net"
 
ARG BUILD_DATE
ARG VCS_REF
ARG BUILD_VERSION

# Labels.
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.build-date=$BUILD_DATE
LABEL org.label-schema.name="wx-rdc/service-base"
LABEL org.label-schema.description="Datahub Service"
LABEL org.label-schema.vcs-ref=$VCS_REF
LABEL org.label-schema.vendor="JNSec Inc."
LABEL org.label-schema.version=$BUILD_VERSION

RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache ca-certificates tzdata
ENV TZ Asia/Shanghai

WORKDIR /app
COPY --from=builder /build/datahub /app

# EXPOSE 设置端口映射
EXPOSE 10003/tcp

# CMD 设置启动命令
CMD ["./datahub", "-env", "fat"]